﻿
(function ($) {
    var jv = window.jv = {};
    if (jv.Request || false == false) {
        jv.Request = {};
        jv.Request.Keys = Array();
    }
    String.prototype.replaceall = function (oldstr, newstr) {
        re = new RegExp(oldstr, "g");
        var ret = this.replace(re, newstr);
        return ret;
    }
    Array.prototype.removeAt = function (n) {
        if (n < 0)
            return this;
        else {
            //return this.slice(0, n).concat(this.slice(n + 1, this.length));
            this.splice(n, 1);
        }
    }
    Array.prototype.pushValue = function (n) {
        if (n < 0)
            return;
        else {
            for (var i = 0; i < n.length; i++) {
                this.push(n[i]);
            }
        }
    }
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) {
                return i;
            }
        }
        return -1;
    }
    Array.prototype.SubIndexOf = function (val) {
        for (var j = 0; j < this.length; j++) {
            if ($.toJSON(this[j]).indexOf(val) > -1)
                return j;
        }
        return -1;
    }
    Array.prototype.removeValue = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    }
    jv.trimValue = function (sor) {
        return $.trim($(sor).val());
    }
    jv.removeHtml = function (s) {
        return (s) ? $("<p>").append(s).text() : "";
    }
    // Ajax 文件下载 
    jv.formNew = function (url, data) {
        if (url && data) {
            var inputs = '';
            $.each(data, function () {
                var pair = this.split('=');
                inputs += '<input type="hidden" name="' + pair[0] + '" value="' + pair[1] + '" />';
            });
            $('<form action="' + url + '" method="post">' + inputs + '</form>').appendTo('body').submit().remove();
        };
    }

    jv.IsInBoxy = function (ev) {
        return $(jv.GetDoer()).parents(".boxy-content:first").length > 0;
    }

    jv.Hide = function (ev) {
        var bo;

        if (ev) {
            var boxy = $(jv.GetDoer()).parents(".boxy-content:first");
            if (boxy.length > 0) {
                bo = Boxy.get("#" + boxy.attr("id"));
            }
        }
        else bo = Boxy.getOne();

        if (bo) {
            bo.hide();
        }
        else if (window.opener != null) {
            window.close();
        }

    }
    String.prototype.trimAll = function () {
        return this.replace(/\s+/g, "");
    }
    String.prototype.endWith = function (str) {
        if (str == null || str == "" || this.length == 0 || str.length > this.length)
            return false;
        if (this.substring(this.length - str.length) == str)
            return true;
        else
            return false;
        return true;
    }
    String.prototype.startWith = function (str) {
        if (str == null || str == "" || this.length == 0 || str.length > this.length)
            return false;
        if (this.substr(0, str.length) == str)
            return true;
        else
            return false;
        return true;
    }
    jv.GetEyeSize = function () {
        return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
    }
    jv.SetDetail = function (selector) {
        $(selector).each(function (i, d) {
            $(this).find(":text,textarea,select").each(function (i, d) {
                var vc = $("<label></label>");
                var vl = d.tagName.toLowerCase() == "select" ? $(d).find("option:selected").text() : $(d).val();
                vc.insertAfter($(d))
                .html(vl)
                .attr("class", $(d).attr("class"))
                .attr("style", $(d).attr("style"));
                $(d).remove();
            });

            $(this).find(":checked").each(function (i, d) {
                if (i > 0) {
                    $(d).after(" , ");
                }
                $(d).remove();
            });

            $(this).find(":radio,:checkbox").each(function (i, d) {
                $("label[for=" + d.id + "]").remove();
                $(d).remove();
            });

            $(this).find(".submit").each(function (i, d) {
                $("<button  class='submit'>关闭</button>")
            .insertAfter($(d))
            .click(function (ev) {
                jv.Hide(ev);
            });
                $(d).remove();
            });

            $(this).find(":file").each(function (i, d) {
                $(d).remove();
            });
        });
    }
    jv.GetDivArray = function (selector, prefixLength) {
        var sr = {};
        $(selector).find("input,textarea,select").each(function (i, d) {
            var nm = d.id || d.name;
            if (jv.IsNull(prefixLength) == false) nm = nm.slice(prefixLength);
            if (jv.IsNull(nm)) return;
            if (typeof (d.value) == "undefined") return;
            if (d.type == "checkbox" || d.type == "radio") {
                if (d.checked == true) {
                    sr[nm] = $.trim(d.value);
                }
                else if (d.type == "checkbox") {
                    sr[nm] = "";
                }
                return;
            }
            sr[nm] = $.trim(d.value);
        });
        return sr;
    }
    jv.GetDivJson = function (selector, prefixLength) {
        var sr = {};
        $(selector).find("input,textarea,select").each(function (i, d) {
            var nm = d.id || d.name;
            if (jv.IsNull(prefixLength) == false) nm = nm.slice(prefixLength);
            if (jv.IsNull(nm)) return;
            if (typeof (d.value) == "undefined") return;
            if (d.type == "checkbox" || d.type == "radio") {
                if (d.checked == true) {
                    sr[nm] = $.trim(d.value);
                }
                else if (d.type == "checkbox") {
                    sr[nm] = "";
                }
                return;
            }
            sr[nm] = $.trim(d.value);
        });
        return $.toJSON(sr);
    }
    jv.GetDivString = function (selector, prefixLength) {
        var sr = "{";
        var ar = {};
        $(selector).find("input,textarea,select").each(function (i, d) {
            var nm = d.id || d.name;
            if (jv.IsNull(prefixLength) == false) nm = nm.slice(prefixLength);
            if (jv.IsNull(nm)) return;
            if (typeof (d.value) == "undefined") return;
            if (d.type == "checkbox" || d.type == "radio") {
                if (d.checked == true) {
                    ar[nm] = $.trim(d.value);
                }
                else if (d.type == "checkbox") {
                    ar[nm] = "";
                }
                return;
            }
            ar[nm] = $.trim(d.value);
            if (i % 100 == 0) {
                if (sr == "{")
                    sr += $.toJSON(ar).replace("{", "").replace("}", "");
                else
                    sr += "," + $.toJSON(ar).replace("{", "").replace("}", "");
                ar = {};
            }
        });
        if (sr != "{")
            return sr += "," + $.toJSON(ar).replace("{", "").replace("}", "") + "}";
        else
            return $.toJSON(ar);
    }
    jv.AllToJson = function (selector, prefixLength) {
        var sr = {};
        $(selector).find("input").each(function (i, d) {
            var push = true;
            var nm = d.name || d.id;
            if (jv.IsNull(prefixLength) == false) nm = nm.slice(prefixLength);
            if (jv.IsNull(nm)) return;
            if (typeof (d.value) == "undefined") return;
            if (d.type == "checkbox") {
                push = false;
                if (d.checked == true) {
                    sr[nm] = $.trim(d.value);
                }
                else {
                    sr[nm] = "";
                }
            }
            if (push) {
                sr[nm] = $.trim(d.value);
            }
        });
        return $.toJSON(sr);
    }

    Array.prototype.forEach = function (callback, thisArg) {
        var T, k;
        if (this == null) {
            throw new TypeError(" this is null or not defined");
        }
        var O = Object(this);
        var len = O.length >>> 0; // Hack to convert O.length to a UInt32  
        if ({}.toString.call(callback) != "[object Function]") {
            throw new TypeError(callback + " is not a function");
        }
        if (thisArg) {
            T = thisArg;
        }
        k = 0;
        while (k < len) {
            var kValue;
            if (k in O) {
                kValue = O[k];
                callback.call(T, kValue, k, O);
            }
            k++;
        }
    };
    jv.SetDivJson = function (selector, prefixLength, JsonValue) {
        $(selector).find("*").each(function (i, d) {
            var nm = d.id;
            if (jv.IsNull(nm)) return;
            if (jv.IsNull(prefixLength) == false) nm = d.id.slice(prefixLength);
            if (jv.IsNull(JsonValue[nm])) return;
            if ($.inArray(d.tagName.toLowerCase(), "input,select,checkbox,textarea,select".split(",")) > -1) {
                $(d).val(JsonValue[nm]);
            }
            else {
                $(d).html(JsonValue[nm]);
            }
        });
    }

    jv.SetDivEmpty = function (selector, prefixLength) {
        $(selector).find("*").each(function (i, d) {
            var nm = d.id;
            if (jv.IsNull(nm)) return;
            if (jv.IsNull(prefixLength) == false) nm = d.id.slice(prefixLength);
            if ($.inArray(d.tagName.toLowerCase(), "input,select,checkbox,textarea,select".split(",")) > -1) {
                $(d).val("");
            }
            else {
                $(d).html("");
            }
        });
    }
    jv.SetArrarValue = function (selector, prefixLength, ArrarValue) {
        $(selector).find("*").each(function (i, d) {
            var nm = d.id;
            if (jv.IsNull(nm)) return;
            if (jv.IsNull(prefixLength) == false) nm = d.id.slice(prefixLength);
            if (jv.IsNull(ArrarValue[nm])) return;
            if ($.inArray(d.tagName.toLowerCase(), "input,select,checkbox,textarea,select".split(",")) > -1) {
                $(d).val(ArrarValue[nm]);
            }
            else {
                $(d).html(ArrarValue[nm]);
            }
        });
    }
    jv.cancelEvent = function (evt) {
        if (window.event) {
            evt.cancelBubble = true;
        } else {
            evt.stopPropagation();
        }
    }

    jv.NameColor = { aliceblue: "#F0F8FF", antiquewhite: "#FAEBD7", aqua: "#00FFFF", aquamarine: "#7FFFD4", azure: "#F0FFFF", beige: "#F5F5DC", bisque: "#FFE4C4", black: "#000000", blanchedalmond: "#FFEBCD", blue: "#0000FF", blueviolet: "#8A2BE2", brown: "#A52A2A", burlywood: "#DEB887", cadetblue: "#5F9EA0", chartreuse: "#7FFF00", chocolate: "#D2691E", coral: "#FF7F50", cornflowerblue: "#6495ED", cornsilk: "#FFF8DC", crimson: "#DC143C", cyan: "#00FFFF", darkblue: "#00008B", darkcyan: "#008B8B", darkgoldenrod: "#B8860B", darkgray: "#A9A9A9", darkgreen: "#006400", darkkhaki: "#BDB76B", darkmagenta: "#8B008B", darkolivegreen: "#556B2F", darkorange: "#FF8C00", darkorchid: "#9932CC", darkred: "#8B0000", darksalmon: "#E9967A", darkseagreen: "#8FBC8B", darkslateblue: "#483D8B", darkslategray: "#2F4F4F", darkturquoise: "#00CED1", darkviolet: "#9400D3", deeppink: "#FF1493", deepskyblue: "#00BFFF", dimgray: "#696969", dodgerblue: "#1E90FF", firebrick: "#B22222", floralwhite: "#FFFAF0", forestgreen: "#228B22", fuchsia: "#FF00FF", gainsboro: "#DCDCDC", ghostwhite: "#F8F8FF", gold: "#FFD700", goldenrod: "#DAA520", gray: "#808080", green: "#008000", greenyellow: "#ADFF2F", honeydew: "#F0FFF0", hotpink: "#FF69B4", indianred: "#CD5C5C", indigo: "#4B0082", ivory: "#FFFFF0", khaki: "#F0E68C", lavender: "#E6E6FA", lavenderblush: "#FFF0F5", lawngreen: "#7CFC00", lemonchiffon: "#FFFACD", lightblue: "#ADD8E6", lightcoral: "#F08080", lightcyan: "#E0FFFF", lightgoldenrodyellow: "#FAFAD2", lightgreen: "#90EE90", lightgrey: "#D3D3D3", lightpink: "#FFB6C1", lightsalmon: "#FFA07A", lightseagreen: "#20B2AA", lightskyblue: "#87CEFA", lightslategray: "#778899", lightsteelblue: "#B0C4DE", lightyellow: "#FFFFE0", lime: "#00FF00", limegreen: "#32CD32", linen: "#FAF0E6", magenta: "#FF00FF", maroon: "#800000", mediumaquamarine: "#66CDAA", mediumblue: "#0000CD", mediumorchid: "#BA55D3", mediumpurple: "#9370DB", mediumseagreen: "#3CB371", mediumslateblue: "#7B68EE", mediumspringgreen: "#00FA9A", mediumturquoise: "#48D1CC", mediumvioletred: "#C71585", midnightblue: "#191970", mintcream: "#F5FFFA", mistyrose: "#FFE4E1", moccasin: "#FFE4B5", navajowhite: "#FFDEAD", navy: "#000080", oldlace: "#FDF5E6", olive: "#808000", olivedrab: "#6B8E23", orange: "#FFA500", orangered: "#FF4500", orchid: "#DA70D6", palegoldenrod: "#EEE8AA", palegreen: "#98FB98", paleturquoise: "#AFEEEE", palevioletred: "#DB7093", papayawhip: "#FFEFD5", peachpuff: "#FFDAB9", peru: "#CD853F", pink: "#FFC0CB", plum: "#DDA0DD", powderblue: "#B0E0E6", purple: "#800080", red: "#FF0000", rosybrown: "#BC8F8F", royalblue: "#4169E1", saddlebrown: "#8B4513", salmon: "#FA8072", sandybrown: "#F4A460", seagreen: "#2E8B57", seashell: "#FFF5EE", sienna: "#A0522D", silver: "#C0C0C0", skyblue: "#87CEEB", slateblue: "#6A5ACD", slategray: "#708090", snow: "#FFFAFA", springgreen: "#00FF7F", steelblue: "#4682B4", tan: "#D2B48C", teal: "#008080", thistle: "#D8BFD8", tomato: "#FF6347", turquoise: "#40E0D0", violet: "#EE82EE", wheat: "#F5DEB3", white: "#FFFFFF", whitesmoke: "#F5F5F5", yellow: "#FFFF00", yellowgreen: "#9ACD32" };
    jv.FormatNumString = function (Num, Length) {
        for (var i = 0; i < Length - Num.length; i++) {
            Num = "0" + Num;
        }
        return Num;
    }
    jv.GetHexColor = function (Color) {
        if (jv.IsNull(Color)) return Color;
        if (Color.indexOf("#") >= 0) return Color;
        if (Color.toLowerCase().indexOf("rgb(") == 0) {
            var cs = Color.substring(4, Color.length - 1).split(",");
            return "#" + jv.FormatNumString(parseInt(cs[0]).toString(16), 2) + jv.FormatNumString(parseInt(cs[1]).toString(16), 2) + jv.FormatNumString(parseInt(cs[2]).toString(16), 2);
        }
        if (Color in jv.NameColor) return jv.NameColor[Color];
        return Color;
    }

    jv.GetOffsetColor = function (Color, Offset) {
        var c = parseInt("0x" + jv.GetHexColor(Color).substr(1));
        var r = (c >> 16) & 0xFF;
        r += parseInt(r * Offset / 255); r = r < 0 ? 0 : r > 255 ? 255 : r;
        var g = (c >> 8 & 0xFF) & 0xFF;
        g += parseInt(g * Offset / 255); g = g < 0 ? 0 : g > 255 ? 255 : g;
        var b = c & 0xFF;
        b += parseInt(b * Offset / 255); b = b < 0 ? 0 : b > 255 ? 255 : b;

        return "#" + jv.FormatNumString(r.toString(16), 2) + jv.FormatNumString(g.toString(16), 2) + jv.FormatNumString(b.toString(16), 2);
    }
    jv.Round = function (Selector, Size) {
        function _PaintCallBack(event) {
            $(event.data.obj).backgroundCanvasPaint(function (context, width, height, elementInfo) {
                var options = { x: 0, height: height, width: width,
                    radius: event.data.radius, border: 0
                };

                context.fillStyle = event.data.borderColor;
                $.canvasPaint.roundedRect(context, options);
                var backgroundGradient = context.createLinearGradient(0, 0, 0, height);
                backgroundGradient.addColorStop(0, jv.GetOffsetColor(event.data.backgroundColor, 0 - event.data.offsetColor));
                backgroundGradient.addColorStop(1, jv.GetOffsetColor(event.data.backgroundColor, event.data.offsetColor));
                options.border = 1;
                context.fillStyle = backgroundGradient;
                $.canvasPaint.roundedRect(context, options);
            })
        }
        var bc;
        var bgc;

        $(Selector).each(function () {
            bc = $(this).css("border-left-color");
            bgc = $(this).css("backgroundColor");
            $(this).backgroundCanvas();
            $(this).bind("mousedown", { obj: this, radius: Size, borderColor: bc, backgroundColor: bgc, offsetColor: 80 }, _PaintCallBack);

            $(this).bind("mouseup", { obj: this, radius: Size, borderColor: bc, backgroundColor: bgc, offsetColor: -80 }, _PaintCallBack);

        });


        $(Selector).trigger("mouseup");
    }


    jv.ESCCode = function (DisplayTxt) {
        var divObj = document.createElement("div");
        $(divObj).html(DisplayTxt);
        return $(divObj).text();
    }
    jv.UnESCCode = function (ESCTxt) {
        var divObj = document.createElement("div");
        $(divObj).text(ESCTxt);
        return $(divObj).html();
    }

    jv.GetRes = function (Key) {
        return jQuery.httpData($.ajax({
            url: jv.Root + "Res.aspx?Key=" + Key + "&Lang=" + (jv.Request["Lang"] || jv.ser["Lang"] || "Zh"),
            async: false,
            dataType: "json"
        }), "json").result;
    }

    jv.InModal = function () {
        if (typeof (window.dialogArguments) != "undefined" && typeof (window.opener) == "undefined") {
            return true;
        }
        return false;
    }

    //判断一个对象是否为空.
    jv.IsNull = function (obj) {
        if (obj == undefined || obj == null || obj == "null" || obj == "") return true;
        if (obj.length != "undefined") {
            return obj.length == 0;
        }
        else return false;
    }

    //取 事件发生源. 兼容FF,IE .
    jv.GetDoer = function () {
        var evt = window.event || arguments.callee.caller.arguments[0];
        var src = evt.srcElement || evt.target;  // 获取触发事件的源对象
        return src;
    }

    jv.ReSet = function () {
        var inputList = $("input");
        inputList.each(function (i) {
            var List = Object();
            List["button"] = true;
            List["hidden"] = true;

            if (jv.IsNull(List[$(inputList[i]).attr("type")]) == false) return;
            $(inputList[i]).val('');
        });

        var inputList = $("select");
        inputList.each(function (i) { inputList[i].selectedIndex = 0; });

        var inputList = $("file");
        inputList.each(function (i) { ClearFileValue($(inputList[i]).attr("id")); });
    }

    ////////////////////////////////////////////////////////////////////////////////////////////
    //改变 网页地址
    jv.TopToUrl = function (url) {
        window.top.location = url;
    }

    //兼容 FF,IE 加载XML文件.
    jv.loadXML = function (xmlpath) {
        var xmlDoc = null;
        if (window.ActiveXObject) {
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        } else if (document.implementation && document.implementation.createDocument) {
            xmlDoc = document.implementation.createDocument("", "", null);
        }
        else {
            alert('Your browser cannot handle this script.');
        }
        xmlDoc.async = false;
        xmlDoc.load(xmlpath);
        return xmlDoc;
    }

    //兼容 FF,IE 下加载数据岛.
    jv.JqLoadXml = function (XmlID) {
        var xmlDoc = $("#" + XmlID);
        if (jv.IsNull(window.ActiveXObject) == true) {
            if (jv.IsNull(xmlDoc.attr("src")) == false) {
                xmlDoc = $(jv.loadXML(xmlDoc.attr("src")));
            }
        }
        return xmlDoc;
    }

    //清除 Input type=file 的值 .
    jv.ClearFileValue = function (FildID) {
        //默认 Input 的 File 的 Value 属性是只读的。
        document.getElementById(FildID).select();
        document.execCommand("Delete");
    }

    ////////////////////////////////////////////////////////////////////////////////////////////

    //IFrame 调用页面后, 自动适应高度的代码.SetWinHeight(this);
    jv.SetWinHeight = function (win, AddExtHeight) {
        if (jv.IsNull(AddExtHeight)) AddExtHeight = 0;
        var ffHeight = win.contentWindow.innerHeight + win.contentWindow.scrollMaxY || 0;
        var ieHeight = 0;
        if (win.document) ieHeight = win.Document.body.scrollHeight || 0;
        if (ieHeight > ffHeight) ffHeight = ieHeight;
        win.height = ffHeight + AddExtHeight;
    }

    jv.LoadJsCss = function (FileType, FileName) {
        var fileref = null;
        if (FileType == "js") {
            var IsHas = false;
            $("script").each(function (i) {
                if ($(this).attr("src") == jv.UnESCCode(FileName)) { IsHas = true; }
                if ($(this).attr("src") == jv.ESCCode(FileName)) { IsHas = true; }
            });
            if (IsHas == true) return;
            //判断文件类型
            fileref = document.createElement('script'); //创建标签
            fileref.setAttribute("type", "text/javascript"); //定义属性type的值为text/javascript
            fileref.setAttribute("src", FileName); //文件的地址
        }
        else if (FileType == "css") {
            var IsHas = false;
            $("link").each(function (i) {
                if ($(this).attr("href") == jv.UnESCCode(FileName)) { IsHas = true; }
                if ($(this).attr("href") == jv.ESCCode(FileName)) { IsHas = true; }
            });
            if (IsHas == true) return;
            //判断文件类型
            fileref = document.createElement("link");
            fileref.setAttribute("rel", "stylesheet");
            fileref.setAttribute("type", "text/css");
            fileref.setAttribute("href", FileName);
        }
        else if (FileType == "deferjs") // defer javascript
        {
            if (jv.IsNull($(FileName)) == true) return;
            fileref = document.createElement('script'); //创建标签
            fileref.setAttribute("type", "text/javascript"); //定义属性type的值为text/javascript
            fileref.text = $(FileName).text();
        }
        else return;

        if (jv.IsNull(fileref) == false) {
            document.getElementsByTagName("head")[0].appendChild(fileref);
        }
    }

    //默认的错误处理, 还未成熟.
    jv.ProcErrors = function () {
        var notReportErrors = Object();
        notReportErrors["Sys.InvalidOperationException: 当 ScriptLoader 已经在加载脚本时，无法调用 ScriptLoader.loadScripts。"] = true;

        if (notReportErrors[arguments[0]] == true) return true;
    }
    jv.AddToFavorite = function (url, title, desc) {
        // 加入收藏夹
        if (document.all) {
            window.external.addFavorite(url, title, desc);
        }
        else if (window.sidebar) {
            window.sidebar.addPanel(title, url, "");
        }
    }

    jv.GetPageSize = function () {
        var scrW, scrH;
        if (window.innerHeight && window.scrollMaxY) {
            // Mozilla
            scrW = window.innerWidth + window.scrollMaxX;
            scrH = window.innerHeight + window.scrollMaxY;
        } else if (document.body.scrollHeight > document.body.offsetHeight) {
            // all but IE Mac
            scrW = document.body.scrollWidth;
            scrH = document.body.scrollHeight;
        } else if (document.body) { // IE Mac
            scrW = document.body.offsetWidth;
            scrH = document.body.offsetHeight;
        }

        var winW, winH;
        if (window.innerHeight) { // all except IE
            winW = window.innerWidth;
            winH = window.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            // IE 6 Strict Mode
            winW = document.documentElement.clientWidth;
            winH = document.documentElement.clientHeight;
        } else if (document.body) { // other
            winW = document.body.clientWidth;
            winH = document.body.clientHeight;
        }

        // for small pages with total size less then the viewport
        var pageW = (scrW < winW) ? winW : scrW;
        var pageH = (scrH < winH) ? winH : scrH;

        return { PageW: pageW, PageH: pageH, WinW: winW, WinH: winH };
    }

    jv.GetPageScroll = function () {
        var x, y;
        if (window.pageYOffset) {
            // all except IE
            y = window.pageYOffset;
            x = window.pageXOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {
            // IE 6 Strict
            y = document.documentElement.scrollTop;
            x = document.documentElement.scrollLeft;
        } else if (document.body) {
            // all other IE
            y = document.body.scrollTop;
            x = document.body.scrollLeft;
        }
        return { X: x, Y: y };
    }

    $.getUrlParamValue = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
    $.getUrlParam = function (name) {
        var UrlParaStr = window.location.search.substr(1);
        var arr = UrlParaStr.split("&");
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].indexOf("=")) {
                var arrs = arr[i].split("=");
                if (arrs[0] == name)
                    return arrs[1];
            }
        }
        return null;
    }
    $.getUrlArray = function () {
        var UrlParaStr = window.location.search.substr(1);
        var arr = UrlParaStr.split("&");
        var urlArr = new Array();
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].indexOf("=")) {
                var arrs = arr[i].split("=");
                if (arrs[1] == "undefined")
                    urlArr[arrs[0]] = "";
                else
                    urlArr[arrs[0]] = arrs[1];
            }
        }
        return urlArr;
    }
    $.toJSON = function (o) {
        if (typeof (JSON) == 'object' && JSON.stringify)
            return JSON.stringify(o);

        var type = typeof (o);

        if (o === null)
            return "null";

        if (type == "undefined")
            return undefined;

        if (type == "number" || type == "boolean")
            return o + "";

        if (type == "string")
            return $.quoteString(o);

        if (type == 'object') {
            if (typeof o.toJSON == "function")
                return $.toJSON(o.toJSON());

            if (o.constructor === Date) {
                var month = o.getUTCMonth() + 1;
                if (month < 10) month = '0' + month;

                var day = o.getUTCDate();
                if (day < 10) day = '0' + day;

                var year = o.getUTCFullYear();

                var hours = o.getUTCHours();
                if (hours < 10) hours = '0' + hours;

                var minutes = o.getUTCMinutes();
                if (minutes < 10) minutes = '0' + minutes;

                var seconds = o.getUTCSeconds();
                if (seconds < 10) seconds = '0' + seconds;

                var milli = o.getUTCMilliseconds();
                if (milli < 100) milli = '0' + milli;
                if (milli < 10) milli = '0' + milli;

                return '"' + year + '-' + month + '-' + day + 'T' +
                             hours + ':' + minutes + ':' + seconds +
                             '.' + milli + 'Z"';
            }

            if (o.constructor === Array) {
                var ret = [];
                for (var i = 0; i < o.length; i++)
                    ret.push($.toJSON(o[i]) || "null");

                return "[" + ret.join(",") + "]";
            }

            var pairs = [];
            for (var k in o) {
                var name;
                var type = typeof k;

                if (type == "number")
                    name = '"' + k + '"';
                else if (type == "string")
                    name = $.quoteString(k);
                else
                    continue;  //skip non-string or number keys

                if (typeof o[k] == "function")
                    continue;  //skip pairs where the value is a function.

                var val = $.toJSON(o[k]);

                pairs.push(name + ":" + val);
            }

            return "{" + pairs.join(", ") + "}";
        }
    };

    /** jQuery.evalJSON(src)
    Evaluates a given piece of json source.
    **/
    $.evalJSON = function (src) {
        if (typeof (JSON) == 'object' && JSON.parse)
            return JSON.parse(src);
        return eval("(" + src + ")");
    };

    /** jQuery.secureEvalJSON(src)
    Evals JSON in a way that is *more* secure.
    **/
    $.secureEvalJSON = function (src) {
        if (typeof (JSON) == 'object' && JSON.parse)
            return JSON.parse(src);

        var filtered = src;
        filtered = filtered.replace(/\\["\\\/bfnrtu]/g, '@');
        filtered = filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']');
        filtered = filtered.replace(/(?:^|:|,)(?:\s*\[)+/g, '');

        if (/^[\],:{}\s]*$/.test(filtered))
            return eval("(" + src + ")");
        else
            throw new SyntaxError("Error parsing JSON, source is not valid.");
    };

    /** jQuery.quoteString(string)
    Returns a string-repr of a string, escaping quotes intelligently.  
    Mostly a support function for toJSON.
    
    Examples:
    >>> jQuery.quoteString("apple")
    "apple"
        
    >>> jQuery.quoteString('"Where are we going?", she asked.')
    "\"Where are we going?\", she asked."
    **/
    $.quoteString = function (string) {
        if (string.match(_escapeable)) {
            return '"' + string.replace(_escapeable, function (a) {
                var c = _meta[a];
                if (typeof c === 'string') return c;
                c = a.charCodeAt();
                return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
            }) + '"';
        }
        return '"' + string + '"';
    };

    var _escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;

    var _meta = {
        '\b': '\\b',
        '\t': '\\t',
        '\n': '\\n',
        '\f': '\\f',
        '\r': '\\r',
        '"': '\\"',
        '\\': '\\\\'
    };
})(jQuery);
 